<template>
  <div class="box">
    <h2>Child222 component</h2>
    <h3>传递过来的数据: {{user.data}}</h3>
  </div>
</template>

<script lang="ts" setup name="Child2">
  import {onBeforeUnmount, reactive} from "vue";
  import emitter from "@/bus/bus";

  interface User {
    name: string
    age: number
  }
  const user = reactive<{data: User}>({
    data: {} as User
  })
  // 绑定事件
  emitter.on('child2Data',(data: User) => {
    user.data = data
  })
  // 组件销毁前
  onBeforeUnmount(()=>{
    emitter.off('child2Data')
  })
</script>

<style scoped>

</style>
